package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumYn;
import com.cw.jeeyt.service.bo.api.ApiFacadeDocBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeDocDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * api接口文档转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiFacadeDocConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeDocBo do2Bo(ApiFacadeDocDo model) {
        if (model == null) {
            return null;
        }
        String isPublicCn = StringUtil.isNotBlank(model.getIsPublicCn()) ? EnumYn.find(model.getIsPublic())
            .getDescription() : "";
        ApiFacadeDocBo bo = new ApiFacadeDocBo();
        bo.setId(model.getId());
        bo.setApiFacadeCode(model.getApiFacadeCode());
        bo.setApiFacadeName(model.getApiFacadeName());
        bo.setApiFacadeVersion(model.getApiFacadeVersion());
        bo.setProjectId(model.getProjectId());
        bo.setProjectCode(model.getProjectCode());
        bo.setProjectName(model.getProjectName());
        bo.setModuleId(model.getModuleId());
        bo.setModuleCode(model.getModuleCode());
        bo.setModuleName(model.getModuleName());
        bo.setApiFacadeMavenConfig(model.getApiFacadeMavenConfig());
        bo.setIsPublic(model.getIsPublic());
        bo.setIsPublicCn(isPublicCn);
        bo.setApiFacadeDesc(model.getApiFacadeDesc());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeDocDo bo2Do(ApiFacadeDocBo bo) {
        if (bo == null) {
            return null;
        }
        ApiFacadeDocDo model = new ApiFacadeDocDo();
        model.setId(bo.getId());
        model.setApiFacadeCode(bo.getApiFacadeCode());
        model.setApiFacadeName(bo.getApiFacadeName());
        model.setApiFacadeVersion(bo.getApiFacadeVersion());
        model.setProjectId(bo.getProjectId());
        model.setProjectCode(bo.getProjectCode());
        model.setProjectName(bo.getProjectName());
        model.setModuleId(bo.getModuleId());
        model.setModuleCode(bo.getModuleCode());
        model.setModuleName(bo.getModuleName());
        model.setApiFacadeMavenConfig(bo.getApiFacadeMavenConfig());
        model.setIsPublic(bo.getIsPublic());
        model.setApiFacadeDesc(bo.getApiFacadeDesc());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeDocBo> doList2BoList(List<ApiFacadeDocDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeDocConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeDocDo> boList2DoList(List<ApiFacadeDocBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeDocConverter::bo2Do));
    }
}
